import { Vector3 } from "stl-typescript";
import { EdgeType } from "../interface";

export class TLine {
  id = -1;
  start: Vector3;
  end: Vector3;
  edgeType: EdgeType = EdgeType.FREE;

  constructor(start: Vector3, end: Vector3, edgeType?: EdgeType, id?: number) {
    this.start = start;
    this.end = end;
    // console.log("start", start);
    // console.log("end", end);
    // console.log("start", typeof start);
    if (id !== undefined) {
      this.id = id;
    }
    if (edgeType !== undefined) {
      this.edgeType = edgeType;
    }
  }

  distanceFromPoint(point: Vector3): number {
    // * A是start起始点 B是end终点 P是point点
    const AB = this.end.clone().sub(this.start.clone());
    const AP = point.clone().sub(this.start.clone());
    const crossRes = AB.cross(AP);
    // console.log("AB", AB);
    // console.log("AP", AP);
    // console.log("crossRes", crossRes);
    // console.log("crossRes", crossRes.length() / AB.length());
    return crossRes.length() / AB.length();
  }
}
